﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using ENTIDADES;

namespace DATA
{
    public class dDetallePedido
    {
        public eJQGrid listadoDetPedido(int idmesa, int idcliente, string sidx, string sord, int page, int rows)
        {

            DataTable dt = MetodoDatos.listaDT("exec uspListarDetalle 1,'DetallePedido', " + idmesa + "," + idcliente + "");

            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize = rows;
            int totalRecords = dt.Rows.Count;
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            var GridData = new eJQGrid
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                    from DataRow dr in dt.Rows
                    select new
                    {
                        i = Convert.ToString(dr["idcabecerapedido"]),
                        cell = new string[]{
                         Convert.ToString(dr["idcabecerapedido"]),                         
                         Convert.ToString(dr["idmesa"]),
                         Convert.ToString(dr["mesa"]),                         
                         Convert.ToString(dr["idcliente"]),                         
                         Convert.ToString(dr["idempleado"]),
                         Convert.ToString(dr["plato"]),
                         Convert.ToString(dr["cantidad"]),
                         Convert.ToString(dr["precio"]),
                         Convert.ToString(dr["importe"]) 
                     }
                    }).ToArray()
            };
            return GridData;
        }

    }
}
